<template>
  <div style="display: flex; margin: 20px">
    <a-input
      style="width: 200px"
      placeholder="请输入查询名字"
      v-model:value="historyParams.name"
    ></a-input>
    <a-button type="primary" style="margin-left: 20px" @click="getHistory()"
      >查询</a-button
    >
  </div>
  <div>
    <!-- 弹框 -->
    <a-modal v-model:visible="visible2" title="修改参数" @ok="rateOk">
      <div class="center" v-if="control">
        <span class="title">设置胜率:</span>
        <a-input v-model:value="updateData.rate" style="width: 340px" />
      </div>
      <div class="center" style="margin-top: 20px" v-else>
        <span class="title">增加金币:</span>
        <a-input v-model:value="addMoney" style="width: 340px" />
      </div>
    </a-modal>
    <!-- 对话框 -->
    <a-modal v-model:visible="visible" title="Basic Modal" @ok="handleOk">
      <a-table
        :columns="detailColumns"
        :data-source="detailsData"
        :rowKey="(record) => record.uid"
        @change="historyChange"
        bordered
      >
      </a-table>
    </a-modal>
    <!-- 表格 -->
    <a-table
      :columns="columns"
      :data-source="historyData"
      :loading="loading"
      :pagination="historyPagination"
      :rowKey="(record) => record.id || record.uid"
      @change="historyChange"
    >
      <template #mem="{ text: men }">
        <span>
          <a @click="details(men)"> 查看对战详情</a>
        </span>
      </template>
      <template #money="{ record: value }">
        <span>
          {{ value.money }} <a @click="setOpem(value, false)"> 增加</a>
        </span>
      </template>
      <template #rate="{ record: value }">
        <span>
          {{ value.rate }} <a @click="setOpem(value, true)"> 设置</a>
        </span>
      </template>
    </a-table>
  </div>
</template>

<script lang="ts">
import Vue, { defineComponent, reactive, toRefs, watch } from "vue";
import { history } from "./hooks";
import { login } from "@/api/user";
export default defineComponent({
  setup() {
    const {
      state,
      getHistory,
      historyChange,
      formatDate,
      handleOk,
      details,
      setOpem,
      rateOk,
    } = history();
    return {
      columns,
      getHistory,
      historyChange,
      formatDate,
      handleOk,
      details,
      setOpem,
      rateOk,
      ...toRefs(state),
      detailColumns,
    };
  },
});
const columns = [
  {
    title: "ID",
    key: "id",
    dataIndex: "id",
    align: "center",
  },

  {
    title: "是否开局",
    key: "start",
    dataIndex: "start",
    align: "center",
  },
  {
    title: "轮数",
    key: "round",
    dataIndex: "round",
    align: "center",
  },
  {
    title: "底注",
    key: "bet",
    dataIndex: "bet",
    align: "center",
  },
  {
    title: "人数(点击查看详情)",
    key: "mem",
    dataIndex: "mem",
    slots: { customRender: "mem" },
    align: "center",
  },
];
const detailColumns = [
  {
    title: "uid",
    key: "uid",
    dataIndex: "uid",
    align: "center",
  },
  {
    title: "剩余金币",
    key: "money",
    dataIndex: "money",
    align: "center",
  },
  {
    title: "是否看牌",
    key: "ready",
    dataIndex: "ready",
    align: "center",
  },
  {
    title: "输赢",
    key: "win",
    dataIndex: "win",
    align: "center",
  },
];
</script>

<style lang="less" scoped>
.table {
  width: 100%;
  overflow-x: hidden;
  overflow-y: scroll;
  background-color: #121c30;
}

.head {
  display: flex;
  width: 300px;
  justify-content: space-between;
  margin-top: -30px;
  margin-bottom: 30px;

  button {
    width: 120px;
    height: 40px;
    font-size: 22px;
  }
}

.on {
  color: #40a9ff;
}

.off {
  color: rgb(47, 45, 45);
}

.col {
  color: red;
}
.title {
  font-size: 18px;
  color: #333;
}
</style>
